package com.mvity.framework.common.global;

import java.io.Serializable;

import com.mvity.framework.common.exception.AppException;
import com.mvity.framework.common.utils.JsonUtil;
import com.mvity.framework.common.utils.XmlUtil;

/**
 * ExtJS Ajax请求响应模型
 * 
 * @author vity
 * @date 2012-9-9
 * @mail vity.1215@gmail.com
 */
public final class ExtJSResponse implements Serializable, IResponseOutput {

	private static final long serialVersionUID = 1085342259882630679L;

	public static ExtJSResponse successResponse = new ExtJSResponse(true, ResultCode.Normal);

	public static ExtJSResponse failureReponse = new ExtJSResponse(false, ResultCode.Failure);

	private boolean success;

	private String resultCode;

	private String msg;
	
	public ExtJSResponse() {
	}

	public ExtJSResponse(boolean success, String resultCode) {
		this.success = success;
		this.resultCode = resultCode;
	}

	public ExtJSResponse(AppException appException) {
		this.success = false;
		this.resultCode = appException.getErrorCode();
		this.msg = appException.getErrorMsg();
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	@Override
	public String toJsonString() {
		return JsonUtil.beanToJson(this);
	}

	@Override
	public String toXmlString() {
		return XmlUtil.beanToXML(this);
	}

	/**
	 * 返回 resultCode 的值
	 * 
	 * @return resultCode
	 */
	public String getResultCode() {
		return resultCode;
	}

	/**
	 * 设置 resultCode 的值
	 * 
	 * @param resultCode
	 */
	public void setResultCode(String resultCode) {
		this.resultCode = resultCode;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
